{% extends "base.html" %}

{% block title %}我的订单{% endblock %}

{% block content %}
<div class="container my-5">
    <div class="card">
        <div class="card-header bg-info text-white">
            <h4>我的订单</h4>
        </div>
        <div class="card-body">
            {% if orders %}
            <div class="table-responsive">
                <table class="table table-hover">
                    <thead>
                        <tr>
                            <th>订单号</th>
                            <th>电影</th>
                            <th>影院</th>
                            <th>时间</th>
                            <th>座位</th>
                            <th>总价</th>
                            <th>状态</th>
                            <th>操作</th>
                        </tr>
                    </thead>
                    <tbody>
                        {% for order in orders %}
                        <tr>
                            <td>{{ order.id }}</td>
                            <td>{{ order.show.movie.title }}</td>
                            <td>{{ order.show.cinema.name }}</td>
                            <td>{{ order.show.start_time.strftime('%Y-%m-%d %H:%M') }}</td>
                            <td>{{ order.seats }}</td>
                            <td>{{ order.total_price }}元</td>
                            <td>
                                {% if order.status == 'paid' %}
                                <span class="badge bg-success">已支付</span>
                                {% elif order.status == 'pending' %}
                                <span class="badge bg-warning">待支付</span>
                                {% elif order.status == 'canceled' %}
                                <span class="badge bg-secondary">已取消</span>
                                {% endif %}
                            </td>
                            <td>
                                <a href="{{ url_for('order_details', order_id=order.id) }}" class="btn btn-sm btn-primary">详情</a>
                                {% if order.status == 'paid' %}
                                <form action="{{ url_for('cancel_order', order_id=order.id) }}" method="post" style="display: inline;">
                                    <button type="submit" class="btn btn-sm btn-danger">取消</button>
                                </form>
                                {% endif %}
                            </td>
                        </tr>
                        {% endfor %}
                    </tbody>
                </table>
            </div>
            {% else %}
            <div class="alert alert-info">您还没有订单记录。</div>
            {% endif %}
        </div>
    </div>
</div>
{% endblock %}